package com.neuedu.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.neuedu.entity.Schedule;
import com.neuedu.mapper.ScheduleMapper;
import com.neuedu.service.ScheduleService;
import com.neuedu.vo.ScheduleCondition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ScheduleServiceImpl extends ServiceImpl<ScheduleMapper, Schedule> implements ScheduleService {

    @Override
    public Page<Schedule> getScheduleList(ScheduleCondition scheduleCondition) {

        Page page = new Page(scheduleCondition.getCurrentPage(), scheduleCondition.getPageSize());

        return this.query()
                .like("schedule_name", scheduleCondition.getScheduleName())
                .page(page);
    }

    @Autowired
    private ScheduleMapper scheduleMapper;

    @Override
    public boolean removeEnable(int scheduleId) {
        return scheduleMapper.findDoctorCount(scheduleId)==0;
    }

    @Override
    public boolean deleteBatch(String scheduleIds) {

        //将字符串拆分成数组  "1,2,3" --> [1,2,3]
        String[] arr = scheduleIds.split(",");

        //字符串数组转换集合  [1,2,3] --> {1,2,3}
        List<Integer> list = new ArrayList<>();

        for (String s : arr) {
            list.add(Integer.parseInt(s));
        }

        return this.removeByIds(list);
    }


}
